import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

enum Api {
  list = '/system-service/microApp/pageMicroApp',
  get = '/system-service/microApp/getMicroApp',
  save='/system-service/microApp/saveMicroApp',
  edit='/system-service/microApp/updateMicroApp',
  deleteMicroApp = '/system-service/microApp/deleteMicroApp',
  deleteBatch = '/system-service/microApp/batchDeleteMicroApp',
  frozenBatch = '/system-service/microApp/frozenBatch',
}

/**
 * 列表接口
 * @param params
 */
export const list = (params) => 
  defHttp.get({url: Api.list, params});

/**
 * @param params
 */
export const getMicroAppDetails = (params) => 
  defHttp.get({url: Api.get, params});


/**
 * 删除应用
 */
export const deleteMicroApp = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteMicroApp, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除应用
 * @param params
 */
export const batchDeleteMicroApp = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新应用
 * @param params
 */
export const saveOrUpdateMicroApp = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}


/**
 * 冻结解冻
 * @param params
 */
export const frozenBatch = (params,handleSuccess) => {
  return defHttp.put({url: Api.frozenBatch, params}).then(() => {
    handleSuccess();
  });
}